package com.ourchem.bus.service.impl;

import java.util.List;
import java.util.stream.Collectors;

import com.ourchem.bus.domain.CollectManage;
import com.ourchem.bus.domain.Course;
import com.ourchem.bus.mapper.CollectManageMapper;
import com.ourchem.common.utils.DateUtils;
import com.ourchem.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ourchem.bus.mapper.LecturerMapper;
import com.ourchem.bus.domain.Lecturer;
import com.ourchem.bus.service.ILecturerService;

/**
 * lecturerService业务层处理
 * 
 * @author xiYan
 * @date 2023-01-12
 */
@Service
public class LecturerServiceImpl implements ILecturerService 
{
    @Autowired
    private LecturerMapper lecturerMapper;
    @Autowired
    private CollectManageMapper collectManageMapper;

    /**
     * 查询lecturer
     * 
     * @param id lecturer主键
     * @return lecturer
     */
    @Override
    public Lecturer selectLecturerById(Long id)
    {
//        return lecturerMapper.selectLecturerById(id);
        Lecturer lecturer = lecturerMapper.selectLecturerById(id);
        CollectManage collectManage = new CollectManage();
        collectManage.setUserId(SecurityUtils.getUserId());
        collectManage.setCollectId(id.toString());
        List<CollectManage> list = collectManageMapper.selectCollectManageList(collectManage);
        if (list.size() > 0) {
            lecturer.setRemark("1");
        } else {
            lecturer.setRemark("0");
        }
        return  lecturer;
    }

    /**
     * 查询lecturer列表
     * 
     * @param lecturer lecturer
     * @return lecturer
     */
    @Override
    public List<Lecturer> selectLecturerList(Lecturer lecturer)
    {
        List<Lecturer> lecturers = lecturerMapper.selectLecturerList(lecturer);

        CollectManage collectManage = new CollectManage();
        lecturers.stream().map(v->{
            collectManage.setUserId(SecurityUtils.getUserId());
            collectManage.setCollectId(v.getId().toString());
            if (collectManageMapper.selectCollectManageList(collectManage).size() > 0) {
                v.setRemark("1");
            } else {
                v.setRemark("0");
            }
            return  v;
        }).collect(Collectors.toList());
        return  lecturers;
    }

    /**
     * 新增lecturer
     * 
     * @param lecturer lecturer
     * @return 结果
     */
    @Override
    public int insertLecturer(Lecturer lecturer)
    {
        lecturer.setCreateTime(DateUtils.getNowDate());
        return lecturerMapper.insertLecturer(lecturer);
    }

    /**
     * 修改lecturer
     * 
     * @param lecturer lecturer
     * @return 结果
     */
    @Override
    public int updateLecturer(Lecturer lecturer)
    {
        lecturer.setUpdateTime(DateUtils.getNowDate());
        return lecturerMapper.updateLecturer(lecturer);
    }

    /**
     * 批量删除lecturer
     * 
     * @param ids 需要删除的lecturer主键
     * @return 结果
     */
    @Override
    public int deleteLecturerByIds(Long[] ids)
    {
        return lecturerMapper.deleteLecturerByIds(ids);
    }

    /**
     * 删除lecturer信息
     * 
     * @param id lecturer主键
     * @return 结果
     */
    @Override
    public int deleteLecturerById(Long id)
    {
        return lecturerMapper.deleteLecturerById(id);
    }
}
